package pattern15;

/**
 * p189
 * 组合模式
 * @author wdl
 */
public class CompositePattern {
    public static void main(String[] args) {
        Composite root=new Composite("root");
        root.add(new Leaf("Leaf A"));
        root.add(new Leaf("Leaf B"));

        Composite composite1=new Composite("Composite1");
        composite1.add(new Leaf("Leaf1 A"));
        composite1.add(new Leaf("Leaf1 B"));

        root.add(composite1);

        Composite composite2=new Composite("Composite2");
        composite2.add(new Leaf("Leaf2 A"));
        composite2.add(new Leaf("Leaf2 B"));

        composite1.add(composite2);

        root.add(new Leaf("Leaf C"));

        Leaf leafD=new Leaf("Leaf D");
        root.add(leafD);

        root.display(1);
    }
}
